package com.terrynoya.fight.stateMachine.controllers
{
	import com.terrynoya.fight.char.Character;
	import com.terrynoya.fight.stateMachine.StateController;
	import com.terrynoya.fight.util.Misc;
	
	public class TargetFacing extends StateController
	{
		public function TargetFacing(name:String)
		{
			super(name);
		}
		
		override public function run(character:Character):void
		{
			var facing:int = this.getAttributeAsInt("value",0);
			var targetId:int = this.getAttributeAsInt("id",int.MIN_VALUE);
			var targetList:Array = character.getTargets(targetId);
			
			for (var i:int = 0; i < targetList.length; i++) 
			{
				var target:Character = targetList[i];
				if(facing > 0)
				{
					target.currentFacing = character.facing;
				}
				else if(facing < 0)
				{
					target.currentFacing = Misc.flipFacing(character.facing);
				}
			}
			
		}
	}
}